
<template>
  <div class="address-box">
    <s-header :name="'地址管理'" :back="'/user'"></s-header>
    <div class="address-item">
      <van-address-list
        v-if="from != 'mine'"
        v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
      />
      <van-address-list
        v-else
        v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
      />
    </div>
  </div>
</template>

<script>
import sHeader from '@/components/SimpleHeader'
export default {
  components: {
    sHeader
  },
  data() {
    return {
      chosenAddressId: '1',
      list: [],
      from: this.$route.query.from,
    }
  },
  created(){
    console.log(this.token)
    let id = this.$cookies.get('id')
 
    this.$axios.get(this.$settings.BASE_URL + 'address/detail/?user_id=' + id,
    {headers:{'Authorization':'jwt ' + this.$cookies.get('token')}}        
     ).then(res=>{
      if(res.code==100){
        for(let i of res.result){
          this.list.push(i)
        }
      }
    })
  },
  methods: {
    onAdd() {
      this.$router.push({ path: `address-edit?type=add&from=${this.from}` })
    },
    onEdit(item) {
      this.$router.push({ path: `address-edit?type=edit&addressId=${item.id}&from=${this.from}` })
    },
  }
}
</script>

<style lang="less">
  @import '../common/style/mixin';

  .address-box {
    .van-radio__icon {
      display: none;
    }
    .address-item {
      margin-top: 44px;
      .van-button {
        background: @primary;
        border-color: @primary;
      }
    }
  }
</style>
